/*
* Copyright © Shanghai Awinic Technology Co., Ltd. 2020-2020. All rights reserved.
* Description: The header file of the TIMER related driver library.
* Date： 20201126
* Awinic_Version： aw_soc_driver_v1.0.0
*/
#include "compile_option.h"
#ifdef AW_86802

#ifndef __AW8680X_TIMER_H
#define __AW8680X_TIMER_H

/* Include ------------------------------------------------------------------*/
#include "aw8680x_def.h"

/**
 * @brief  Timer Initialization Configuration Structure definition
**/
struct timer_init_type_struct {
	AW_U32 timer_load_count;
	AW_U32 timer_mode;
};
typedef struct timer_init_type_struct TIMER_INIT_TYPE_S;

/**
 * @brief  TIMER Configuration Structure definition
**/
struct timer_handle_struct {
	IRQn_Type timer_irq_e;				// TIMER irq number
	IRQ_PRI_E timer_irq_pri_e;			// TIMER irq priority
	TIMER_TYPE_S *p_instance_s;			// TIMER registers base address
	TIMER_INIT_TYPE_S init_s;			// TIMER communication parameters
};
typedef struct timer_handle_struct TIMER_HANDLE_TYPE_S;

/* TIMER Instances */
#define TIMER_CHECK_INSTANCE(instance) (((instance) == TIMER0) || ((instance) == TIMER1))
/* TIMER timer mode */
#define TIMER_CHECK_MODE(mode) (((mode) == TIME_USER_MODE) || ((mode) == TIME_FREE_MODE))

#define TIME_MASK_EN		((AW_U32)0x00000004)
#define TIME_MASK_DIS		(~TIME_MASK_EN)
#define TIME_USER_MODE		((AW_U32)0x00000002)
#define TIME_FREE_MODE		(~TIME_USER_MODE)
#define TIME_EN				((AW_U32)0x00000001)
#define TIME_DIS			(~TIME_EN)
#define TIME_STAT			((AW_U32)0x00000001)

RET_STATUS_E timer_enable(TIMER_HANDLE_TYPE_S *p_timer_lib);
RET_STATUS_E timer_disable(TIMER_HANDLE_TYPE_S *p_timer_lib);
RET_STATUS_E timer_init(TIMER_HANDLE_TYPE_S *p_timer_lib);
RET_STATUS_E timer_irq(TIMER_HANDLE_TYPE_S *p_timer_lib);
RET_STATUS_E timer_set_load_cnt(TIMER_TYPE_S *p_tim, AW_U32 load_cnt);
void timer0_irq_call(TIMER_HANDLE_TYPE_S *p_timer_lib);
void timer1_irq_call(TIMER_HANDLE_TYPE_S *p_timer_lib);

#endif
#endif
